#include<iostream>
#include<queue>
#include<string.h>
using namespace std;
const int N=110;
typedef pair<int,int> PII;
int n,m,ans;
int g[N][N],dis[N][N];
PII pre[N][N];
int main()
{
    cin>>n>>m;
    for(int i=0;i<n;++i)
        for(int j=0;j<m;++j) scanf("%d",&g[i][j]);
    memset(dis,-1,sizeof dis);
    queue<PII> Q;
    int dics[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
    dis[0][0]=0;
    Q.emplace(0,0);
    while(!Q.empty())
    {
        auto [x,y]=Q.front();Q.pop();
        for(auto dic:dics)
        {
            int newx=x+dic[0],newy=y+dic[1];
            if(newx>=0&&newx<n&&newy>=0&&newy<m&&g[newx][newy]==0&&dis[newx][newy]==-1)
            {
                Q.emplace(newx,newy);
                pre[newx][newy]={x,y};
                dis[newx][newy]=dis[x][y]+1;
            }
        }
    }
    int x=n-1,y=m-1;
    while(x||y)
    {
        cout<<x<<" "<<y<<endl;
        auto t=pre[x][y];
        x=t.first,y=t.second;
    }
    return 0;
}